package com.ksc.service.impl;

import com.ksc.entity.Password;
import com.ksc.mapper.PasswordMapper;
import com.ksc.service.PassportService;
import com.ksc.util.CheckPassportUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class PassportServiceImpl implements PassportService {

    @Autowired
    private PasswordMapper passwordMapper;

    //生成一个修改密码的链接
    @Override
    public void resetPasswordLink() {

    }

    @Override
    public void CheckRecordPassword(String acc, String old, String password) {
        CheckPassportUtil checkPassportUtil = new CheckPassportUtil();
        if (checkPassportUtil.changePswd(acc, old, password)) {
            System.out.println("密码修改成功");
            Password pd = new Password();
            pd.setPassword(password);
            pd.setAccount(acc);
            pd.setRecordTime(LocalDateTime.now());
            passwordMapper.insert(pd);
        } else {
            System.out.println("密码修改失败");

        }
    }

    @Override
    public boolean CheckPasswordValidity(String account) {
        CheckPassportUtil checkPassportUtil = new CheckPassportUtil();
        LocalDateTime passwordTime =passwordMapper.selectByAccount(account).getRecordTime();
        return checkPassportUtil.CheckPasswordValidity(passwordTime, LocalDateTime.now());
    }
}
